/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.component.tabbedPane;

import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.plaf.metal.MetalTabbedPaneUI;

import com.ruipengkj.commons.util.Util;
/**
 * 说明：
 * 重写MetalTabbedPaneUI
 * @Author：李智深
 * @Date：2012-07-04
 */
public class RPTabbedPaneUI extends MetalTabbedPaneUI {

    private RPTabbedPane tab = null;
    private int firstTabIndent = 5;

    public RPTabbedPaneUI(RPTabbedPane tab) {
        this.tab = tab;
    }

    @Override
    protected Rectangle getTabBounds(int tabIndex, Rectangle dest) {
        Rectangle bounds = super.getTabBounds(tabIndex, dest);
        //give first tab a leading space.
        bounds.x += firstTabIndent;
        return bounds;
    }

    @Override
    protected void paintTabBorder(Graphics g, int tabPlacement,
            int tabIndex, int x, int y, int w, int h,
            boolean isSelected) {

        //paint nothing, expect the bottom line in the leading indent.
        g.setColor(Util.TAB_BOTTOM_LINE_COLOR);
        int lineY = tab.getPreferredTabHeight() - 1;
        g.drawLine(0, lineY, firstTabIndent, lineY);
    }

    @Override
    protected void paintTabBackground(Graphics g, int tabPlacement,
            int tabIndex, int x, int y, int w, int h,
            boolean isSelected) {
        //paint nothing
    }

    @Override
    protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
        int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
        //use this to remove the tab between tabs.
        return width - 5;
    }

    @Override
    protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
        return tab.getPreferredTabHeight();
    }
}
